library SoundSystemLegacy initializer init requires GlobalVariables

	globals
		private group G = null
	endglobals
	
	function SetVolForP takes player p, real v returns nothing
		if GetLocalPlayer()==p then
			call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_UNITSOUNDS,v*.7)
			call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_SPELLS,v)
			call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_COMBAT,v)
			call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_FIRE,v)
			call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_UI,v)
			call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_AMBIENTSOUNDS,v)
		endif
	endfunction

	function PlaySoundPath takes nothing returns nothing //by Anitarf & Infrane
		local sound s = CreateSound(udg_soundpath, false, false, false, 10, 10, "DefaultEAXON")
		call SetSoundChannel(s,3)
		call StartSound(s)
		call TriggerSleepAction(12.)
		call KillSoundWhenDone(s)
		set s = null
	endfunction
	
	function PlaySoundPathForPlayer takes player p returns nothing //by Anitarf & Infrane
		local sound s = CreateSound(udg_soundpath, false, false, false, 10, 10, "DefaultEAXON")
		call SetSoundChannel(s,3)

		call SetSoundVolume(s, 0)
		call StartSound(s)

		if GetLocalPlayer() == p then
			call SetSoundVolume(s, 127)
		endif

		call TriggerSleepAction(12.)
		call KillSoundWhenDone(s)
		set s = null
	endfunction
	
	
	globals
		private sound array earshock
	endglobals
	
	private function EarshockE takes nothing returns boolean
		local player p 
		local sound s
		if IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) then
			set p = GetOwningPlayer(GetFilterUnit())
			set s = earshock[GetPlayerId(p)]

			call StopSound(s, false, false)
			call StartSound(s)

			if GetLocalPlayer() == p then
				call SetSoundVolume(s, 127)
			else
				call SetSoundVolume(s, 0)
			endif
			
		endif
		set p = null
		set s = null
		return false
	endfunction

	function EarShockArea takes real x, real y, real radius returns nothing
		call GroupEnumUnitsInRange(G, x,y, radius, Condition(function EarshockE))
	endfunction

	function PlaySoundPath3D takes nothing returns nothing
		local sound s = CreateSound( udg_soundpath, false, true, false, 10, 10, "DefaultEAXON" )
		call SetSoundDuration(s,565)
		call SetSoundChannel(s,0)
		call SetSoundVolume(s,udg_Sound3DVolume)
		call SetSoundPitch(s,1.0)
		call SetSoundDistances(s,600.0,10000.0)
		call SetSoundDistanceCutoff(s,3000.0)
		call SetSoundConeAngles(s, 0.0, 0.0, 127 )
		call SetSoundConeOrientation(s, 0.0, 0.0, 0.0 )
		call SetSoundPosition(s, bj_meleeNearestMineDist, bj_lastTransmissionDuration, 0)
		call StartSound(s)
		call TriggerSleepAction(12.)
		call KillSoundWhenDone(s)
		set s = null
	endfunction

	function PumpShotgun takes unit u returns nothing
		set bj_meleeNearestMineDist = GetUnitX(u)
		set bj_lastTransmissionDuration = GetUnitY(u)
		set udg_soundpath = "war3mapImported\\m3_pump.wav"
		call PlaySoundPath3D.execute()
	endfunction

	function RifleBolt takes unit u returns nothing
		set bj_meleeNearestMineDist = GetUnitX(u)
		set bj_lastTransmissionDuration = GetUnitY(u)
		set udg_soundpath = "war3mapImported\\m4a1_boltpull.wav"
		call PlaySoundPath3D.execute()
	endfunction

	function GeneralEquipment takes unit u returns nothing
		set bj_meleeNearestMineDist = GetUnitX(u)
		set bj_lastTransmissionDuration = GetUnitY(u)
		set udg_soundpath = "war3mapImported\\CombatKnife.wav"
		call PlaySoundPath3D.execute()
	endfunction

	function MachineGunLink takes unit u returns nothing
		set bj_meleeNearestMineDist = GetUnitX(u)
		set bj_lastTransmissionDuration = GetUnitY(u)
		set udg_soundpath = "war3mapImported\\AmmoLink.mp3"
		call PlaySoundPath3D.execute()
	endfunction

	private function init takes nothing returns nothing
		local integer i = 0
		local sound s
		set G = CreateGroup()
		loop
			exitwhen i > 11
			set s = CreateSound("war3mapImported\\ring4.mp3", false, false, false, 10, 10, "DefaultEAXON")
			call SetSoundChannel(s, 5)
			call SetSoundVolume(s, 127)
			call SetSoundPitch(s, 1.)
			set earshock[i] = s
			set i = i + 1
		endloop
	endfunction

endlibrary